<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/commons/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<%@ include file="/commons/head.jsp" %>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <%@ include file="/commons/left.jsp" %>
    <div class="content-wrapper">
        <section class="content-header">
            <h1>
                新增文章
            </h1>
        </section>
        <div class="content">
            <div class="row">
                <div class="col-md-9">
                    <div class="box box-primary" style="overflow:hidden">
                        <form class="form-horizontal" autocomplete="off" enctype="multipart/form-data"
                              id="addArticleForm" method="post">
                            <input type="hidden" name="id" value="${article.id}">
                            <div class="box-body" style="padding-top:30px">
                                <div class="form-group">
                                    <label for="inputTitleName" class="col-sm-2 control-label">文章标题</label>
                                    <div class="col-sm-5">
                                        <input type="text" class="form-control" autocomplete="off" id="inputTitleName"
                                               name="title" value="${article.title}" placeholder="请输文章标题">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="multipartFile" class="col-sm-2 control-label">文章封面图片</label>
                                    <div class="col-sm-5">
                                        <input type="file" class="form-control" autocomplete="off"
                                               id="multipartFile" name="multipartFile" value="${article.articleImage}"
                                               placeholder="请文章封面图片">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="inputAuther" class="col-sm-2 control-label">作者</label>
                                    <div class="col-sm-3">
                                        <input type="text" class="form-control" id="inputAuther" name="auther"
                                               value="${article.auther}" placeholder="请输入作者">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="inputFileFrom" class="col-sm-2 control-label">文章来源</label>
                                    <div class="col-sm-3">
                                        <input type="text" class="form-control" id="inputFileFrom" name="fileFrom"
                                               value="${article.fileFrom}" placeholder="请输文章来源">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="inputAbstracts" class="col-sm-2 control-label">文章简介</label>
                                    <div class="col-sm-3">
                                        <input type="text" class="form-control" id="inputAbstracts" name="abstracts"
                                               value="${article.abstracts}" placeholder="请输文章简介">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="inputDescribes" class="col-sm-2 control-label">页面描述</label>
                                    <div class="col-sm-3">
                                        <input type="text" class="form-control" id="inputDescribes" name="describes"
                                               value="${article.describes}" placeholder="请输页面描述">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="selectArticleStatus" class="col-sm-2 control-label">状态</label>
                                    <div class="col-sm-3">
                                        <select class="form-control select2 select2-hidden-accessible"
                                                id="selectArticleStatus"
                                                style="width: 100%;" tabindex="-1" aria-hidden="true"
                                                name="articleStatus">
                                            <option value="1"
                                                    <c:if test="${1 == article.articleStatus}">selected="selected"</c:if>>
                                                发布
                                            </option>
                                            <option value="0"
                                                    <c:if test="${0 == article.articleStatus}">selected="selected"</c:if>>
                                                未发布
                                            </option>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="selectArticleOrder" class="col-sm-2 control-label">推荐位置</label>
                                    <div class="col-sm-3">
                                        <select class="form-control select2 select2-hidden-accessible"
                                                id="selectArticleOrder"
                                                style="width: 100%;" tabindex="-1" aria-hidden="true"
                                                name="articleOrder">
                                            <option value="1"
                                                    <c:if test="${1 == article.articleOrder}">selected="selected"</c:if>>
                                                列表显示
                                            </option>
                                            <option value="0"
                                                    <c:if test="${0 == article.articleOrder}">selected="selected"</c:if>>
                                                首页显示
                                            </option>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="inputKeyword" class="col-sm-2 control-label">关键词</label>
                                    <div class="col-sm-3">
                                        <input type="text" class="form-control" id="inputKeyword" name="keyword"
                                               value="${article.keyword}" placeholder="请输关键词">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="selectCategoryId" class="col-sm-2 control-label">文章分类</label>
                                    <div class="col-sm-3">
                                        <select class="form-control select2 select2-hidden-accessible"
                                                id="selectCategoryId"
                                                style="width: 100%;" tabindex="-1" aria-hidden="true" name="categoryId">
                                            <option value="0">请选择</option>
                                            <c:forEach var="category" items="${listSysArticleCategory}" varStatus="vs">
                                                <option value="${category.id}"
                                                        <c:if test="${category.id == article.categoryId}">selected="selected"</c:if>>${category.categoryName}</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="content" class="col-sm-2 control-label">文章内容</label>
                                    <div class="col-sm-10">
                                        <script type="text/plain" id="content" name="content">${article.content}</script>
                                    </div>
                                </div>
                            </div>
                            <div class="box-footer">
                                <div class="col-sm-2"></div>
                                <button type="button" class="btn btn-info" onclick="submitForm()">提交</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <%@ include file="/commons/script.jsp" %>
    <script src="${ctx}/dist/js/jquery.form.js?version=1.1"></script>
    <script charset="utf-8" src="${ctx}/ueditor/ueditor.config.js"></script>
    <script charset="utf-8" src="${ctx}/ueditor/ueditor.all.min.js"></script>
    <script charset="utf-8" src="${ctx}/ueditor/lang/zh-cn/zh-cn.js"></script>
    <script type="text/javascript">
        var ue = UE.getEditor('content', {
            initialFrameWidth: 700,
            initialFrameHeight: 300,
            wordCount: true,
            elementPathEnabled: false
        });
        function submitForm() {
            var id = $('#addArticleForm').find('input[name=id]').val();
            var url = null;
            if (id == null || id == "") {
                url = "${ctx}/article/addSysArticle?action=add";
            } else {
                url = "${ctx}/article/addSysArticle?action=update";
            }
            $("#addArticleForm").ajaxSubmit({
                cache: false,
                type: "post",
                url: url,
                /*data: $('#postForm').serialize(),// formid*/
                error: function () {
                    alert("系统异常");
                },
                success: function (data) {
                    if (data !== null) {
                        if (data == 0) {
                            //修改失败
                            alert('失败');
                        } else {
                            //添加/修改成功
                            alert('成功');
                        }
                        window.location.href="${ctx}/article/listArticle"
                    }
                }
            });
        }
    </script>
</body>
</html>
